VB 如何自定义"yyyy-mm-dd"中的yyyy

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:59:20
比如:

date1="2009-5-1"

怎么能在text1中单独定义其中的“2009”,比如我在text1中输入“2011”,date1就变成"2011-5-1"?

新手提问, 多谢高手回答!!

在text1中输入“2011”,date1就变成"2011-5-1"?
str=Val(Text1.text)
date1=format(str & "-5-1","YYYY-MM-DD")
或者你在text1中输入“2011-6-18"的话,date1就变成"2011-5-1"?
str=Text1.text
str=left(str,4)
date1=format(str & "-5-1","YYYY-MM-DD")

那你的设置选择的时候只要选择的是year就可以了 不要把那些都设置出来 不要用now什么之类的

用format函数

要么就直接用text.change事件进行设置

不难

Private Sub Command1_Click()
Dim a As String
Dim date1 As date
Dim str As String
a = "-5-1"
str = Text1.Text + a
date1=Format(str, "yyyy-mm-dd")
MsgBox date1
End Sub